package com.zmx.gateway.utils;

import java.util.*;

/**
 * @Description: 轮询
 * @ClassName: RoundRobin
 * @Author zhaomxr
 * @Date 2021-12-22 15:36
 */
public class RoundRobinUtil {

    //当前轮询的节点 从0开始
    private static Integer code = 0;

    public static String get(List<String> nodeList) {

        String node = "";
        synchronized (code) {
            //如果当前轮询节点已到最大值，从0开始重新计算
            if (code >= nodeList.size()) {
                code = 0;
            }
            node = nodeList.get(code);
            code++;
        }

        return node;
    }
}
